<?php 
// 引入模型
use Common\Model\Category;
$data=new Category;
// 获取导航条   内容
$menu=$data->where('is_hot',1)->limit(7)->get();
foreach ($menu as $k => $v) {
    $menu[$k]['goods']=Db::table('goods')->where('category_cid',$v['cid'])->limit(2)->get();
}
    	
// 获取数据  男装  女装
$cateData=$data->where('pid',0)->limit(2)->get();
// 重组数组
foreach ($cateData as $k => $v) {
	$cateData[$k]['two']=$data->where('pid',$v['cid'])->get();
}
foreach ($cateData as $k => $v) {
	foreach ($v['two'] as $kk => $vv) {
		$cateData[$k]['two'][$kk]['three']=$data->where('pid',$vv['cid'])->get();
	}
}
// p($cateData);


// 获取数据 鞋袜
$shoe=$data->where('cid',3)->get();
// 声明空数组
$shoeData=array();
foreach ($shoe as $k => $v) {
	$shoeData=$data->where('pid',$v['cid'])->get();
}

 ?>
<!--顶部灰色区域-->
		<div id="top">
			<div class="header">
				<div class="header_left">
					<div class="welcome">
			            您好,
			            {{if value="isset($_SESSION['hname'])"}}
			            <span><a href="" style="color:#A10000;">{{$_SESSION['hname']}}</a> <a href="{{U('Login/out')}}" style="color:#A10000;"> 退出登陆 </a> | <a href="{{U('Login/tab')}}" style="color:#A10000;">切换用户</a></span>
			            {{else}}
			            欢迎光临凡客诚品！
			            <span><a href="{{U('Login/login')}}">登录</a> | <a href="{{U('Register/register')}}">注册</a></span>
			            {{endif}}
			            </div>
					<div class="collect">
						{{if value="isset($_SESSION['hname'])"}}
						<a href="{{U('Member/dingdan')}}">我的订单</a>
						{{else}}
						<a href="{{U('Login/login')}}">我的订单</a>
						{{endif}}
						<a href="">收藏本站</a>
					</div>
				</div>
				<div class="header_right">
					<ul>
						<li>
							<a href="{{U('Member/index')}}">我的凡客<span></span></a>
							<div class="listBox">
								<a href="{{U('Member/index')}}">我的凡客<span></span></a>
								<ul style="clear: both;">
									<li><a href="{{U('Member/dingdan')}}">我的订单</a></li>
									<li><a href="">我的收藏</a></li>
								</ul>
							</div>
						</li>
						<li>
							<a href="">帮助中心<span></span></a>
							<div class="listBox">
								<a href="">帮助中心<span></span></a>
								<ul>
									<li><a href="">购物指南</a></li>
									<li><a href="">配送方式</a></li>
									<li><a href="">支付方式</a></li>
									<li><a href="">售后服务</a></li>
									<li><a href="">投诉建议</a></li>
									<li><a href="">在线客服</a></li>
								</ul>
							</div>
						</li>
						<li>
							<a href="">网站公告<span></span></a>
							<div class="listBox">
		                        <a href="">网站公告<span></span></a>
		                        <ul>
		                            <li><a href="">春节公告</a></li>
		                            <li><a href="">网站公告</a></li>
		                            <li><a href="">重要提示</a></li>
		                        </ul>
		                    </div>
						</li>
						<li><a href="">手机凡客<span class="tel"></span></a></li>
						<li><a href="">在线客服<span class="line"></span></a></li>
					</ul>
					<a href="" class="weibo"></a>
					<a href="" class="weixin"></a>
				</div>
			</div>
		</div>
		<!--顶部灰色区域结束-->
		<!--搜索区域-->
		<script type="text/javascript">
        $(function(){
            $(document).on("mouseenter", ".carttop", function(){ 
                // alert(1);
                $.ajax({
                    url: '{{U('Index/ajaxCart')}}',
                    type: 'POST',
                    dataType: 'json',
                    data: {param1: 'value1'},
                    success:function(arr){
                        console.log(arr);
                        if(arr.goods.length!=0){
                            tr = '<a href="index.php?m=Home&c=car&a=index" class="carttop">购物车（'+arr.total_rows+'）</a><div class="index_2"></div><div class="index_1">最近加入的商品：<br /><ul>';
                            $.each(arr.goods, function(k, v) {
                                tr += '<li><input type="hidden" name="gid" value="'+k+'" /><div><img src="'+v.pic+'" alt="" /></div><div><a href="index.php?m=Home&c=Desc&a=index&gid='+v.id+'" class="gname">'+v.name+'&nbsp;';
                                    $.each(v.options, function(kk, vv) {
                                        tr += vv;
                                    });
                                tr += '</a><p class="price"> ￥'+v.price+'×'+v.num+'</p></div><div class="gdel"><a href="javascript:;" class="cardel">删除</a></div></li>';
                            });
                            tr += '</ul><div class="total"><p>共计(未计算促销折扣)<br />￥'+arr.total+'</p><a href="index.php?m=Home&c=car&a=index" class="showcart">查看购物车（'+arr.total_rows+'）</a></div></div>';
                            $('.shoppingcart').html(tr);
                        }else{
                            tr = '<a href="index.php?m=Home&c=car&a=index" class="carttop">购物车（0）</a><div class="index_2"></div><div class="index_1">您的购物车中没有任何商品</div>';
                            $('.shoppingcart').html(tr);
                        }
                    }
                })
            });
        })
        // 异步删除购物车中的商品
        // 高版本下不支持live事件  用on代替
        $(function(){
            $(document).on("click", ".cardel", function(){ 
                var _this=$(this);
                // alert(1);
                // 获得商品序号
                var gid = $(this).parents('li').find('input[name=gid]').val();
                // alert(gid);
                $.ajax({
                    url: '{{U('Index/ajaxDel')}}',
                    type: 'POST',
                    dataType: 'json',
                    data: {gid: gid},
                    success:function(arr){
                        if(arr.total!=0){
                            tr = '购物车（'+arr.total+'）';
                            $('.shoppingcart .carttop').text(tr);
                            $('.shoppingcart .total').html('<p>共计(未计算促销折扣)<br />￥'+arr.total+'</p><a href="index.php?m=Home&c=car&a=index" class="showcart">查看购物车（'+arr.total_rows+'）</a>')
                            _this.parents('li').remove();
                        }else{
                            tr = '<a href="index.php?m=Home&c=car&a=index" class="carttop">购物车（0）</a><div class="index_2"></div><div class="index_1">您的购物车中没有任何商品</div>';
                            $('.shoppingcart').html(tr);
                        }
                    }
                })
            });
        })
    </script>
		<div id="seek">
			<div class="logo">
				<a href="{{U('Index/index')}}"></a>
			</div>
			<div class="search_">
				<div class="searchTab">
					<form action="" method="post">
						<input type="text" class="searchTab_1" placeholder="搜“羽绒服”，体验与众不同" />
						<input type="submit" value="" class="searchTab_2" />
					</form>
					<div class="shoppingcart">
                {{if value="isset($_SESSION['cart']['goods']) && !empty($_SESSION['cart']['goods'])"}}
                    <a href="{{U('Car/index')}}" class="carttop">购物车（{{$_SESSION['cart']['total_rows']}}）</a>
                    <div class="index_2"></div>
                    <div class="index_1">最近加入的商品：<br />
                        <ul>
                            {{foreach from="$_SESSION['cart']['goods']" key="$k" value="$v"}}
                            <li>
                                <input type="hidden" name="gid" value="{{$k}}" />
                                <div><img src="{{$v['pic']}}" alt="" /></div>
                                <div>
                                    <a href="{{U('Desc/index',array('gid'=>$v['id']))}}" class="gname">{{$v['name']}}</a>
                                    <p class="price"> ￥{{$v['price']}}×{{$v['num']}}</p>
                                </div>
                                <div class="gdel">
                                    <a href="javascript:;" class="cardel">删除</a>
                                </div>
                            </li>
                            {{endforeach}}
                        </ul>
                        <div class="total">
                            <p>共计(未计算促销折扣)<br />￥{{$_SESSION['cart']['total']}}</p>
                            <a href="{{U('Car/index')}}" class="showcart">查看购物车（{{$_SESSION['cart']['total_rows']}}）</a>
                        </div>
                    </div>
                {{else}}
                    <a href="index.php?m=Home&c=car&a=index" class="carttop">购物车（0）</a>
                    <div class="index_2"></div>
                    <div class="index_1">您的购物车中没有任何商品</div>
                {{endif}}
            </div>
				</div>
				<div class="searchText">
					热门搜索：<a href="">羽绒服</a><a href="">外套</a><a href="">衬衫</a><a href="">针织衫</a><a href="">帆布鞋</a>
				</div>
			</div>
		</div>
		<!--搜索区域结束-->
		<!--导航条-->
		<div id="menu">
			<div class="all" style="position: relative;">全部商品分类
				<span></span>
				<div class="all_menu">

				<!-- 控制单独样式 -->
		        <script type="text/javascript">
		            $(function(){
		                $('.all_menu div dl dd a:first-child').removeClass('index');
		            })
		        </script>
				<!-- 男装 女装 -->
					<?php foreach ($cateData as $k=>$v){ ?>
					<div>
					<dl>
						<h4><a href="{{U('List/index',array('cid'=>$v['cid']))}}" target="_blank"><?php echo $v['cname'] ?></a></h4>
						<?php foreach ($v['two'] as $kk => $vv) { ?>
							<dt><a href="{{U('List/index',array('cid'=>$vv['cid']))}}" target="_blank"><?php echo $vv['cname'] ?></a></dt>
							<dd>
								<?php foreach ($vv['three'] as $kkk=>$vvv){ ?>
								<a href="{{U('List/index',array('cid'=>$vvv['cid']))}}" target="_blank" class="index"><?php echo $vvv['cname'] ?></a>
								<?php } ?>
							</dd>
						<?php } ?>
					</dl>
					</div>
					<?php } ?>
				<!-- 鞋袜 -->
					<div>
					<dl>
						<h4>
							<?php foreach ($shoeData as $k=>$v){ ?>
				            <a href="{{U('List/index',array('cid'=>$v['cid']))}}" target="_blank" style="float:left;"><?php echo $v['cname'] ?>/</a>
				            <?php } ?>
						</h4>
						<dd>
							<?php foreach ($shoeData as $k=>$v){ ?>
				            <a href="{{U('List/index',array('cid'=>$v['cid']))}}" target="_blank" class="index"><?php echo $v['cname'] ?></a>
				            <?php } ?>
						</dd>
					</dl>
					</div>
				</div>	
			</div>
			<ul>
				<?php foreach ($menu as $k=>$v){ ?>
				<li>
					<a href="{{U('List/index',array('cid'=>$v['cid']))}}" class="fir_menu"><?php echo $v['cname'] ?></a>
					<div class="sec_menu">
						<?php foreach ($v['goods'] as $kk => $vv){?>
						<div class="sec_menu_clo">
							<img src="<?php echo $vv['pic'] ?>" />
							<h3><a href="{{U('Desc/index',array('gid'=>$vv['gid']))}}"><?php echo $vv['gname'] ?></a></h3>
							<span>￥<?php echo $vv['sprice'] ?></span>
						</div>
						<div class="sec_menu_line"></div>
						<?php } ?>
					</div>
				</li>
				<?php } ?>
				<li><a href="" class="fir_menu">特惠频道</a></li>
			</ul>
		</div>
		<!--导航条结束-->